package com.jy.rhin.infra.cda.dao.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jy.rhin.facade.cda.dto.ReqDto;
import com.jy.rhin.infra.cda.dao.ZhuYuanZhaiYaoDao;
import com.jy.rhin.infra.cda.mapper.ZhuYuanZhaiYaoMapper;
import com.jy.rhin.infra.cda.zyzy.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dhl
 * @date 2023/2/13
 * @Description
 */
@Service
public class ZhuYuanZhaiYaoDaoImpl implements ZhuYuanZhaiYaoDao {
    @Resource
    private ZhuYuanZhaiYaoMapper zhuYuanZhaiYaoMapper;

    @Override
    public ZhuYuanInfoVo queryZhuYuanInfo(ReqDto req){
        QueryWrapper<ZhuYuanInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("ZHUYUANJZLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryZhuYuanInfo(queryWrapper);
    }

    @Override
    public List<JianChaInfoVo> queryJianChaList(ReqDto req){
        QueryWrapper<JianChaInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("JIUZHENLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryJianChaList(queryWrapper);
    }

    @Override
    public List<JianYanInfoVo> queryJianYanList(ReqDto req){
        QueryWrapper<JianChaInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.JIUZHENLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryJianYanList(queryWrapper);
    }

    @Override
    public ZhenDuanInfoVo queryZhenDuan(ReqDto req){
        QueryWrapper<ZhenDuanInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.ZHUYUANJZLSH", req.getJiuZhenLSH());
        queryWrapper.last(" limit 1 ");
        return zhuYuanZhaiYaoMapper.queryZhenDuan(queryWrapper);
    }

    @Override
    public HuiZhenInfoVo queryHuiZhen(ReqDto req) {
        QueryWrapper<HuiZhenInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("ZHUYUANJZLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryHuiZhen(queryWrapper);
    }

    @Override
    public JianKangPingGuInfoVo queryJianKangPingGu(ReqDto req) {
        QueryWrapper<JianKangPingGuInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.ZHUYUANJZLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryJianKangPingGu(queryWrapper);
    }

    @Override
    public JianKangZhiDaoInfoVo queryJianKangZhiDao(ReqDto req) {
        QueryWrapper<JianKangZhiDaoInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("ZHUYUANJZLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryJianKangZhiDao(queryWrapper);
    }

    @Override
    public List<ZhuYuanYZVo> queryYongYao(ReqDto req) {
        QueryWrapper<ZhuYuanYZVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("ZHUYUANJZLSH", req.getJiuZhenLSH());
        queryWrapper.eq("YIZHULX", "01");
        return zhuYuanZhaiYaoMapper.queryYongYao(queryWrapper);
    }

    @Override
    public ZhuYuanZZVO queryZhuanZhen(ReqDto req) {
        QueryWrapper<ZhuYuanZZVO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.ZHUANRUJGBH", req.getYiLiaoJGDM());
        //queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.ZHUYUANJZLSH", req.getJiuZhenLSH());
        return zhuYuanZhaiYaoMapper.queryZhuanZhen(queryWrapper);
    }

    @Override
    public List<FeiYongInfoVo> queryFeiYong(ReqDto req){
        QueryWrapper<FeiYongInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("a.YUANQUID", req.getYuanQuID());
        queryWrapper.eq("a.ZHUYUANJZLSH", req.getJiuZhenLSH());
        queryWrapper.isNotNull("b.MINGXIFYLB");
        return zhuYuanZhaiYaoMapper.queryFeiYong(queryWrapper);
    }

    @Override
    public List<ShouShuInfoVo> queryShouShuList(ReqDto req) {
        QueryWrapper<ShouShuInfoVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("YILIAOJGDM", req.getYiLiaoJGDM());
        queryWrapper.eq("YUANQUID", req.getYuanQuID());
        queryWrapper.eq("JIUZHENLSH", req.getJiuZhenLSH());
        queryWrapper.and(wrapper -> wrapper.eq("MENJIZZYBZ", 3));
        return zhuYuanZhaiYaoMapper.queryShouShuList(queryWrapper);
    }

}
